<!DOCTYPE html>

<html>

<head>

    <!-- 页面meta -->

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>帖子管理</title>

    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/test2.css">
<!--    <link rel="stylesheet" href="../css/test.css">-->

    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">

    <link rel="stylesheet" href="../plugins/elementui/style2.css">



</head>

<body class="hold-transition">

<div id="app">
<!--    style="background-color: #6f7180"-->
    <div class="content-header" >

<!--        <h1 style="background-color: #6f7180;text-align: center;font-family: 'PingFang SC';line-height:1 " >AGE客栈 </h1>-->
        <div class="line"></div>
        <el-menu
                :default-active="activeIndex2"
                class="el-menu-demo"
                mode="horizontal"
                @select="handleSelect"
                background-color="#545c64"
                text-color="#fff"
               >
            <el-menu-item index="4"
            style="font-size: 20px"
            ><a href="http://139.9.241.51:8282/login">AGE客栈</a></el-menu-item>
        </el-menu>
    </div>


    <div class="app-container">
        <div class="left"  style="width: 200px">

                <el-menu
                        style="min-height: calc(85vh)"
                        default-active="2-1"
                        class="el-menu-vertical-demo"
                        @open="handleOpen"
                        @close="handleClose"
                        background-color="#545c64"
                        text-color="#fff"
                        active-text-color="#ffd04b">
                    <a href="http://139.9.241.51:8282/index">
                    <el-menu-item index="1">
                        <i class="el-icon-menu"></i>
                        <span slot="title">数据中心</span>
                    </el-menu-item>
                    </a>
                    <el-submenu index="2">
                        <template slot="title">
                            <i class="el-icon-document"></i>
                            <span style="text-align: center">内容管理</span>
                        </template>
                        <el-menu-item-group>
                            <el-menu-item index="2-1">帖子管理</el-menu-item>
                            <el-menu-item index="2-2">申诉管理</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>

<!--                    <el-menu-item index="3" disabled>-->
<!--                        <i class="el-icon-document"></i>-->
<!--                        <span slot="title">导航三</span>-->
<!--                    </el-menu-item>-->
                    <el-menu-item index="4">
                        <i class="el-icon-setting"></i>
                        <span slot="title">平台设置 </span>
                    </el-menu-item>
                </el-menu>

           </div>
        <div class="box" style="flex: 1">


            <div class="filter-container" >

                <el-input placeholder="用户名称" v-model="pagination.name" style="width: 200px;" class="filter-item" clearable ></el-input>
                <el-input placeholder="文章名称" v-model="pagination.title" style="width: 200px;" class="filter-item"></el-input>
                <el-input placeholder="发表时间" v-model="pagination.time" style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="getAll()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
<!--            <a href="http://139.9.241.51:8282/print">-->
<!--                <el-button type="info" class="dalfBut">打印</el-button>-->
<!--            </a>-->
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>

                <el-table-column prop="id" align="center" label="序号"></el-table-column>

                <el-table-column prop="name" label="姓名" align="center"></el-table-column>

                <el-table-column prop="sex" label="性别" align="center"></el-table-column>

                <el-table-column prop="title" label="文章标题" align="center"></el-table-column>

                <el-table-column prop="type" label="类型" align="center"></el-table-column>

                <el-table-column prop="readamount" label="阅读量" align="center"></el-table-column>

                <el-table-column prop="likeamount" label="点赞量" align="center"></el-table-column>

                <el-table-column prop="colloectamount" label="收藏量" align="center"></el-table-column>

                <el-table-column prop="time" label="发表时间" align="center"></el-table-column>


                <el-table-column label="操作" align="center">

                    <template slot-scope="scope">

                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>

                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>

                    </template>

                </el-table-column>

            </el-table>

            <!--分页组件-->
            <div class="pagination-container">

                <el-pagination
                        class="pagiantion"

                        @current-change="handleCurrentChange"

                        :current-page="pagination.currentPage"

                        :page-size="pagination.pageSize"

                        layout="total, prev, pager, next, jumper"

                        :total="pagination.total">

                </el-pagination>

            </div>

            <!-- 新增标签弹层 -->

            <div class="add-form">

                <el-dialog title="帖子管理" :visible.sync="dialogFormVisible">

                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                        <el-row>

                            <el-col :span="10">

                                <el-form-item label="姓名:" prop="name">

                                    <el-input v-model="formData.name"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="6">

                                <el-form-item label="性别:" prop="sex">

                                    <el-input v-model="formData.sex"/>

                                </el-form-item>

                            </el-col>
                            <el-col :span="16">

                                <el-form-item label="文章标题:" prop="title">

                                    <el-input v-model="formData.title"/>

                                </el-form-item>

                            </el-col>
                            <el-col :span="14">

                                <el-form-item label="类型:" prop="type">

                                    <el-input v-model="formData.type"/>

                                </el-form-item>

                            </el-col>

                        </el-row>


                        <el-row>

                            <el-col :span="6">

                                <el-form-item label="阅读量" prop="readamount">

                                    <el-input v-model="formData.readamount" ></el-input>

                                </el-form-item>

                            </el-col>
                            <el-col :span="8">

                                <el-form-item label="点赞量" prop="likeamount">

                                    <el-input v-model="formData.likeamount" ></el-input>

                                </el-form-item>
                            </el-col>
                            <el-col :span="14">

                                <el-form-item label="收藏量" prop="colloectamount">

                                    <el-input v-model="formData.colloectamount" ></el-input>

                                </el-form-item>

                            </el-col>

                            <el-col :span="20">

                                <el-form-item label="发表时间" prop="time">

                                    <el-input v-model="formData.time" ></el-input>


                                </el-form-item>

                            </el-col>
                        </el-row>

                    </el-form>

                    <div slot="footer" class="dialog-footer">

                        <el-button @click="cancel()">取消</el-button>

                        <el-button type="primary" @click="handleAdd()">确定</el-button>

                    </div>

                </el-dialog>

            </div>

            <!-- 编辑标签弹层 -->

            <div class="add-form">

                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">

                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                        <el-row>

                            <el-col :span="10">

                                <el-form-item label="姓名" prop="name">

                                    <el-input v-model="formData.name"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="6">

                                <el-form-item label="性别" prop="sex">

                                    <el-input v-model="formData.sex"/>

                                </el-form-item>

                            </el-col>
                            <el-col :span="14">

                                <el-form-item label="文章标题" prop="title">

                                    <el-input v-model="formData.title"/>

                                </el-form-item>

                            </el-col>
                            <el-col :span="12">

                                <el-form-item label="类型" prop="type">

                                    <el-input v-model="formData.type"/>

                                </el-form-item>

                            </el-col>
                            <el-col :span="6">

                                <el-form-item label="阅读量" prop="readamount">

                                    <el-input v-model="formData.readamount"/>

                                </el-form-item>

                            </el-col>
                            <el-col :span="10">

                                <el-form-item label="点赞量" prop="likeamount">

                                    <el-input v-model="formData.likeamount"/>

                                </el-form-item>

                            </el-col>
                            <el-col :span="14">

                                <el-form-item label="收藏量" prop="colloectamount">

                                    <el-input v-model="formData.colloectamount"/>

                                </el-form-item>

                            </el-col>
                        </el-row>

                        <el-row>

                            <el-col :span="24">

                                <el-form-item label="发表时间" prop="time">

                                    <el-input v-model="formData.time" ></el-input>

                                </el-form-item>

                            </el-col>

                        </el-row>

                    </el-form>

                    <div slot="footer" class="dialog-footer">

                        <el-button @click="cancel()">取消</el-button>

                        <el-button type="primary" @click="handleEdit()">确定</el-button>

                    </div>

                </el-dialog>

            </div>
        </div>

    </div>

</div>

</body>

<!-- 引入组件库 -->

<script src="../js/vue.js"></script>

<script src="../plugins/elementui/index.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>

<script src="../js/axios-0.18.0.js"></script>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            dataList: [],//当前页要展示的列表数据
            dialogFormVisible: false,//添加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            formData: {},//表单数据
            rules: {//校验规则
                type: [{ required: true, message: '姓名为必填项', trigger: 'blur' }],
                name: [{ required: true, message: '文章内容为必填项', trigger: 'blur' }]
            },
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:6,//每页显示的记录数
                total:0,//总记录数
                title:"",
                name:"",
                time:""
            }
        },

        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.getAll();
        },

        methods: {
            // //列表
            // getAll() {
            //     //发送异步请求
            //     axios.get("/Summary").then((res)=>{
            //         // console.log(res.data)
            //         this.dataList=res.data.data;
            //     });
            // },
            getAll(){
                //组织参数，拼接Url请求地址
                param="?query";
                param+="&title="+this.pagination.title;
                param+="&name="+this.pagination.name;
                param+="&time="+this.pagination.time;

              axios.get("/Summary/"+this.pagination.currentPage+"/"+this.pagination.pageSize+param).then((res)=>{
                  this.pagination.pageSize=res.data.data.size;
                  this.pagination.currentPage=res.data.data.current;
                  this.pagination.total=res.data.data.total;
                  this.dataList=res.data.data.records;
              })
            },

            //分页查询

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage=currentPage;
                this.getAll();
            },

            //弹出添加窗口
            handleCreate() {
                this.dialogFormVisible=true;
                this.resetForm();
            },

            //重置表单
            resetForm() {
                this.formData={};
            },

            //添加
            handleAdd() {
                axios.post("/Summary", this.formData).then((res) => {
                    //判断当前操作是否成功
                    if(res.data.flag){
                        this.dialogFormVisible = false;
                        this.$message.success(res.data.msg);}
                    //1.关闭弹层
                    else{
                        this.$message.error(res.data.msg);
                    }

                }).finally(() => {
                    //2.重新加载数据
                    this.getAll();
                })
            },

            //取消
            cancel(){
                this.dialogFormVisible4Edit=false;
                this.dialogFormVisible=false;
                this.$message.info("操作取消");
            },
            // 删除
            handleDelete(row) {
             this.$confirm("是否确定删除?","提示",{type:"info"}).then(()=>{
                 axios.delete("/Summary/"+row.id).then((res)=>{
                     this.$message.success("删除成功");
                 }).finally(()=>{
                     this.getAll();
                 })
             }).catch(()=>{
                 this.$message.info("操作取消")
             })
            },

            //弹出编辑窗口
            handleUpdate(row) {
                axios.get("/Summary/"+row.id).then((res)=>{
                   if(res.data.flag && res.data.data !=null){
                       this.dialogFormVisible4Edit=true;
                       this.formData=res.data.data;
                   }
                   else{
                       this.$message.error("数据编辑失败，重新加载数据..")
                   }
                }).finally(()=>{
                    this.getAll();
                })
            },

            //修改
            handleEdit() {
                axios.put("/Summary",this.formData).then((res)=>{
                    if(res.data.flag){
                        this.dialogFormVisible4Edit=false;
                        this.$message.success("修改成功");
                    }
                    else{
                        this.$message.error("修改失败");
                    }
                }).finally(()=>{
                    this.getAll();
                })
            },



            //条件查询
        }
    })

</script>

</html>